package xcmg.device.dao.mapper.warehouse;


import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;
import xcmg.device.dao.entity.warehouse.WarehouseInventoryDO;
import xcmg.device.service.vo.initialInventory.MaterialsEnableStock;
import xcmg.device.service.vo.warehouse.FindMaterialsNumParam;
import xcmg.device.service.vo.warehouse.FindMaterialsNumVO;
import xcmg.device.service.vo.warehouse.InventoryMaterialsSearchVO;
import xcmg.device.service.vo.warehouse.InventoryMaterialsVO;
import xcmg.device.service.vo.warehouse.MaterialNoAndAmountsVO;
import xcmg.device.service.vo.warehouse.SafeInventoryVO;
import xcmg.device.service.vo.warehouse.StockAmountInfo;
import xcmg.device.service.vo.warehouse.WarehoseIntentionDetialVO;
import xcmg.device.service.vo.warehouse.WarehouseInventoryVO;
import xcmg.device.service.vo.warehouse.app.WarehouseInventoryBatchTransferVO;
import xcmg.device.service.vo.wechat.MaterialsInventoryVO;
import xcmg.device.service.warehouse.WarehouseAreaStockQueryParamVO;
import xcmg.device.service.warehouse.WarehouseAreaStockQueryResultVO;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface WarehouseInventoryMapper {
    int deleteByPrimaryKey(String id);

    int insert(WarehouseInventoryDO record);

    WarehouseInventoryDO selectByPrimaryKey(String id);

    WarehouseInventoryDO selectByBarCode(@Param("barCode") String barCode, @Param("orgId") String orgId);

    List<WarehouseInventoryDO> selectByBarCodeList(@Param("barCodes") List<String> barCodes, @Param("orgId") String orgId, @Param("frozen") Integer frozen);

    int updateByPrimaryKeySelective(WarehouseInventoryDO record);

    List<WarehouseInventoryDO> list(WarehouseInventoryVO model);

    int remove(@Param("ids") List<String> ids);

    Map<String, Object> selectForCount(@Param("materialNo") String materialNo, @Param("orgId") String orgId);

    int updateByLocation(WarehouseInventoryDO record);

    List<WarehouseInventoryDO> listForMaterial(WarehouseInventoryVO model);

	List<WarehouseInventoryDO> listWithKeeper(WarehouseInventoryVO model);

    List<WarehouseInventoryDO> listWithKeeperForExport(WarehouseInventoryVO model);

    int findCountForExportAllKeeper(WarehouseInventoryVO model);

    List<InventoryMaterialsVO> invenitoryMaterialsList(InventoryMaterialsSearchVO model);

    List<InventoryMaterialsVO> invenitoryMaterialsListByBarcode(InventoryMaterialsSearchVO model);

    BigDecimal findEnableNum(@Param("materialNo") String materialNo, @Param("orgId") String orgId, @Param("wahouseCode")String wahouseCode);

    List<FindMaterialsNumVO> findMaterialsNum(FindMaterialsNumParam findMaterialsNumParam);

    int locationCodeCount(WarehouseInventoryBatchTransferVO recode);

    List<WarehouseInventoryDO> listForMaterialDetail(WarehouseInventoryVO model);

    List<WarehouseInventoryDO> listForCollect(WarehouseInventoryVO model);

    List<WarehouseInventoryDO> listForPDA(WarehouseInventoryVO model);

    List<SafeInventoryVO> ListForSafe(SafeInventoryVO model);

    int ListForSafeCount(SafeInventoryVO model);

    int earliestInventory(@Param("orgId")String orgId, @Param("materialNo")String materialNo, @Param("warehouseCode")String warehouseCode,
                          @Param("areaCode")String areaCode, @Param("createDate")Date createDate);

    int removeByBarcodeList(@Param("barcodeList") List<String> barcodeList, @Param("orgId") String orgId);

    int updateInboundByBarcodeList(@Param("barcodeList") List<String> barcodeList, @Param("orgId") String orgId);

    List<WarehouseInventoryDO> listForQueryDetail(WarehouseInventoryVO model);

    List<MaterialsInventoryVO> companyInventory(@Param("orgId")String orgId,@Param("materialsDes")String materialsDes, @Param("machineType")String machineType);

    Integer countCompanyMaterials(@Param("orgId")String orgId,@Param("materialsDes")String materialsDes, @Param("machineType")String machineType);

    List<WarehoseIntentionDetialVO> intentionDetailList(WarehoseIntentionDetialVO model);

    List<WarehoseIntentionDetialVO> deliveryDetailList(WarehoseIntentionDetialVO model);

    List<String> findLocationCode(@Param("orgId")String orgId, @Param("materialNo")String materialNo, @Param("warehouseCode")String warehouseCode, @Param("areaCode")String areaCode);

    String findInventoryLocationCode(@Param("materialNo") String materialNo, @Param("warehouseCode") String warehouseCode, @Param("orgId") String orgId,@Param("areaCode") String areaCode);

    List<WarehouseInventoryDO> listForDealer(WarehouseInventoryVO model);

    List<WarehouseInventoryDO> exportListForDealer(WarehouseInventoryVO model);

    int listCountForDealer(WarehouseInventoryVO model);

    List<StockAmountInfo> listStockAmountInfo(StockAmountInfo stockAmountInfo);

    BigDecimal getAvailableNum(@Param("materialNo") String materialNo, @Param("orgId") String orgId);

    /**
     * 查询零件正常库存数量
     *
     * @param materialsNo
     * @param orgId
     * @return
     */
    BigDecimal countStock(@Param("materialsNo") String materialsNo, @Param("orgId") String orgId);

    /**
     * 获取所有状态库存
     * @param materialsNo
     * @param orgId
     * @return
     */
    BigDecimal getInventoryQty(@Param("materialsNo") String materialsNo, @Param("orgId") String orgId);


    /**
     * 获取零件可用库存
     *
     * @param orgId
     * @param materialsNo
     * @return
     */
    MaterialsEnableStock countEnableInventory(@Param("orgId") String orgId, @Param("materialsNo") String materialsNo);

    /**
     * 统计货架上的库存数量（用来判断货架能不能重新创建。不区分零件和库存状态，只要又库存就不允许）
     *
     * @param warehouseCode
     * @param areaCode
     * @param locationCodePre
     * @param orgId
     * @return
     */
    BigDecimal countByLocationCode(@Param("warehouseCode")String warehouseCode, @Param("areaCode")String areaCode,
            @Param("locationCodePre")String locationCodePre, @Param("orgId")String orgId);

    /**
     * 根据储位和零件编码删除零件
     * @param warehouseInventoryDO
     * @param materialNos
     * @return
     */
    int deleteByLocationCodeAndMaterialNos(@Param("warehouseInventoryDO")WarehouseInventoryDO warehouseInventoryDO, @Param("materialNos")List<String> materialNos);


    /**
     * 根据储位和零件编码更新零件数量
     * @param warehouseInventoryDO
     * @param materialNo
     * @return
     */
    int updateAmountByLocationCodeAndMaterialNo(@Param("warehouseInventoryDO") WarehouseInventoryDO warehouseInventoryDO, @Param("materialNo") String materialNo, @Param("amount") BigDecimal amount);

    List<WarehouseInventoryDO> listByMaterialNos(@Param("orgId")String orgId, @Param("locationCode")String localtionCode, @Param("materialNos")List<MaterialNoAndAmountsVO> materialNos);

    /**
     * 根据储位编号与零件编码进行更新
     * @param record 零件DO
     * @return
     */
    int updateByLocationAndMaterialNo(WarehouseInventoryDO record);

    /**
     * 根据零件id集合查询其对应的中心仓库库存
     * @param materialNos
     * @param orgId
     * @return
     */
    List<WarehouseInventoryDO> queryCentralInventoryByMeterialIds(@Param("materialNos") List<String> materialNos, @Param("orgId") String orgId);

    /**
     * 根据零件编码和公司id修改呆滞零件状态
     * @param materialNo
     * @param orgId
     * @return
     */
    boolean updateSluggishFlagByMaterialNoAndOrgId(@Param("materialNo") String materialNo,@Param("orgId") String orgId,@Param("sluggishShardFlag") String sluggishShardFlag);

    List<WarehouseInventoryDO> selectByMaterialNoAndOrgId(@Param("materialNo") String materialNo,@Param("orgId") String orgId);

    /**
     * @Des 查询库区库存报表
     * @Date 2020/11/10 17:35
     * @Author wangzhaoyu
     * @Param [filters]
     * @Return java.util.List<xcmg.device.service.warehouse.WarehouseAreaStockQueryResultVO>
     */
    List<WarehouseAreaStockQueryResultVO> selectWarehouseAreaStock(WarehouseAreaStockQueryParamVO filters);

    boolean deductInventoryByMaterialsNo(@Param("materialsNo") String materialsNo,@Param("orgId") String orgId);
}
